<?php
/**
 * 会员控制器
 * Created by Forever.
 * User: Forever
 * Date: 2018/10/03
 * Time: 上午 10:39
 */
namespace app\api\controller;
use think\Controller;
use think\Request; 
use \think\Db;
use think\Validate;
use think\Loader;
class Sms extends Base{
	public function _initialize() {
	  parent::_initialize ();
	}


	public function send(){
		$data = $this->data;
		$expiresIn = 15*60;
		// 发送短信提醒
		header('Content-Type: text/plain; charset=utf-8');
		$mobile = $data['phone'];
		$code = rand(100000,999999);
		$result = cache($mobile);
		if(empty($result) || $result['last_time']<time()){
	        $alisms = new \alisms\AlismsHandler();
            $response = $alisms->sendSingleSms($mobile,['code'=>$code],1);
	        if($response['status'] == 1){
			$res['last_time'] = time() + $expiresIn;
			$res['code'] = $code;
			cache($mobile, $res);
		    }
		    return api_return(10009);
	    }else{
	    	 return api_return(-10035);
	    }
     }
}
